<?php
/**
 *Help Model
 *Loads the help content 
 *
 *@author S.Feil, T.Ziegler, M.El-Hindi <goatymail@googlemail.com>
 *27 May 2012
 *@copyright Copyright (c) 2012, S.Feil, T.Ziegler, M.El-Hindi
 *@package cms
 *
 */
/**
 *Class Help_Model
 *
 *@package model
 */
class Help_Model extends Model{
    /**
     * Gets the text from database (standard return values / errors)
     * @var object
     */
    private $oTextModel;
        /**
     * Holds connection to database
     * @var object
     */
    protected $oDBInstance;
    
    /**
     * Model constructor
     * Establishes connection to database and loads textmodel
     */
    public function __construct(){
        $this->oDBInstance = Mysql_dbconnection::getInstance();
        $this->oTextModel = Loader::loadModel('textLanguage');
    }

/**
 * Loads the title of the help page
 * @param string controller name
 * @param integer language
 */
    public function getHelpTitle($sController, $iLanguage){
        $iPage = $this->oDBInstance->getSQLValueString($sController,'string');
        //Asks the database for the help title
        $this->oDBInstance->query("SELECT name FROM `bs_page_help` WHERE cms = 0 AND controller='$sController' AND lid='$iLanguage';");
        $aResult = $this->oDBInstance->fetch('array');
        if(isset($aResult[0]['name'])){
        return $aResult[0]['name'];
        }else{
            return "";
        }
    }
/**
 * Gets the help text / content 
 * @param string controller 
 * @param integer language
 */
    public function getHelpContent($sController, $iLanguage){
        $iPage = $this->oDBInstance->getSQLValueString($sController,'string');
        $this->oDBInstance->query("SELECT content FROM `bs_page_help` WHERE cms = 0 AND controller='$sController' AND lid='$iLanguage';");
        $aResult = $this->oDBInstance->fetch('array');
        if(isset($aResult[0]['content'])){
        return $aResult[0]['content'];
        }else{
            return $this->oTextModel->getTextByName('nohelp', $iLanguage);
        }
    }
}
